#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   4.py
@Time    :   2020/04/21 22:01:25
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# 在当前目录新建目录img, 里面包含10个文件, 10个文件名各不相同(X4G5.png) 将当前img目录所有以.png结尾的后缀名改为.jpg.
# Start typing your code from here

import os

try:
    files = os.listdir('homework3\img')
    # path = os.getcwd()
    for filename in files:
        portion = os.path.splitext(filename)
        if portion[1] == ".img":
            newname = portion[0] + ".png"
            os.rename(filename,newname)
except IOError:
    print("ERROR!")
    